<template>
	<view class="content bg-drak ft-main">
		<use-navbar :title="title"></use-navbar>
		<view class="row dflex padding-lr" v-if="formData.adress">
			<text class="tit">地址</text>
			<text class="tit" style="flex: 1;">{{formData.adress}}</text>
			<!-- <view class="iconfont icondizhi- input_t padding-lr-sm padding-tb-16"></view>-->
		</view>
		<view class="row dflex padding-lr" v-if="formData.mobile">
			<text class="tit">电话</text>
			<text class="tit" style="flex: 1;">{{formData.mobile}}</text>
		</view>
		<view class="row dflex padding-lr" v-if="formData.email">
			<text class="tit">邮箱</text>
			<text class="tit" style="flex: 1;">{{formData.email}}</text>
		</view>
		<view class="row dflex padding-lr" v-if="formData.wechat">
			<text class="tit">微信号</text>
			<text class="tit" style="flex: 1;">{{formData.wechat}}</text>
		</view>
		<view class="padding-lr">业务咨询</view>
		<view class="row dflex padding-lr">
			<text class="tit">姓名</text>
			<input class="input" v-model="sumbitData.name" placeholder="请输入姓名" placeholder-class="placeholder" />
		</view>
		<view class="row dflex padding-lr">
			<text class="tit">手机号</text>
			<input class="input" type="number" v-model="sumbitData.mobile" placeholder="请输入手机号码"
				placeholder-class="placeholder" />
		</view>
		<view class="padding-lr">售后顾问将跟您电话确认服务时间和具体项目</view>

		<view class="padding w-full margin-top-big">
			<view class="dflex-b border-radius-big">
				<view class="tac padding-tb-sm flex1 bg-base" @click="submit">提交</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		mapState
	} from 'vuex';
	const mini_obj = uniCloud.importObject('wmz-mini')
	export default {
		data() {
			return {
				title: '业务咨询',
				formData: {},
				sumbitData: {}
			};
		},
		onLoad(options) {
			uni.setNavigationBarTitle({
				title: this.title
			});
			this.loadData()
		},
		methods: {
			async loadData() {
				const res = await mini_obj.getContact({
					shop_id: uni.getStorageSync('wmzmall_user_shop_id')
				})
				if (res.code === 200) {
					this.formData = res.data
				}

			},
			//提交
			async submit() {
				if (!this.sumbitData.name) {
					this.$api.msg('请输入姓名');
					return;
				}
				if (!/(^1[3|4|5|6|7|8|9][0-9]{9}$)/.test(this.sumbitData.mobile)) {
					this.$api.msg('请输入正确的手机号码');
					return;
				}
				this.sumbitData.app_id = uni.getStorageSync('wmzmall_user_app_id')
				this.sumbitData.shop_id = uni.getStorageSync('wmzmall_user_shop_id')
				const res = await mini_obj.addConsult(this.sumbitData)
				if (res.code === 200) {
					this.$api.msg('提交成功');
					this.sumbitData={}
				}else{
					this.$api.msg('提交失败,请稍后重试');
				}
			}
		}
	};
</script>

<style lang="scss">
	page {
		background: $page-color-base;
	}

	.row {
		background: #fff;
		position: relative;
		height: 110rpx;
		margin: 20rpx;
		border-radius: 20rpx;

		.tit {
			flex-shrink: 0;
			width: 150rpx;
		}

		.input {
			flex: 1;
			font-size: 30rpx;
			padding-left: 0;
		}

		.input_t {
			color: #333;
		}
	}
</style>